import { encryptValue } from '@/utils/encryptValue'
import type * as I from './interface'
import { http } from '@/server'

export const loginApi = async (params: I.LoginFormType) => {
    try {
        const { password } = params
        const encryptedPassword = encryptValue(password)
        const { data } = await http.post<I.LoginRes>('/oauth/token-mobile', {
            ...params,
            password: encryptedPassword,
        })
        return data
    } catch (error) {
        return undefined
    }
}

/** 忘记密码 */
export const forgetPasswordApi = async (data: {
    phone: string
    password: string
    confirm_password: string
    sms_code: string
    request_id: string
}) => {
    const { password } = data
    const encryptedPassword = encryptValue(password)
    return http.put('/oauth/forget-password', { ...data, password: encryptedPassword })
}
